﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using HK2009.Common;
using HK2009.BusinessFacade;
using HK2009.BusinessFacadeHandler;
using HK2009.EntityQuery;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;

public partial class SystemManage_PlaceUpdate :  BasePage
{
    ISyPlaceHandler placeManager = new SyPlaceHandler();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["UserID"] != null)
            {
                ISystemHandler sysManage = new SystemHandler();
                string strPermission = sysManage.GetLoginUserPermissions();
                if (!strPermission.Contains("1013"))
                {
                    Response.Redirect("~/NotPurview.aspx");
                    return;
                }
            }           

            dataBind();
        }
    }
    private void dataBind()
    {

        if (Request["PKID"] != null)
        {
            Sy_PlaceQuery query = placeManager.GetPlaceByID(int.Parse(Request["PKID"]));
            if (query != null)
            {
                //txtCode.Text = query.Code;
                txtHKName.Text = query.HKName;
                txtENName.Text = query.ENGName;
                txtName.Text = query.Name;
                txtRemark.Text = query.Remark;
                txtDistrict.Text = query.District;
                txtHKDistrict.Text = query.HKDistrict;
                txtENDistrict.Text = query.ENGDistrict;
                if (query.Status ==0)
                {
                    radNo.Checked = true;
                    radYes.Checked = false;
                }
                else
                {
                    radNo.Checked = false;
                    radYes.Checked = true;
                }

            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Request["PKID"] != null)
        {
            Sy_PlaceQuery placeQuery = placeManager.GetPlaceByID(int.Parse(Request["PKID"]));
            if (placeQuery != null)
            {
                placeQuery.Name = txtName.Text.Trim();
                placeQuery.ENGName = txtENName.Text.Trim();
                placeQuery.HKName = txtHKName.Text.Trim();
                placeQuery.District = txtDistrict.Text.Trim();
                placeQuery.ENGDistrict = txtENDistrict.Text.Trim();
                placeQuery.HKDistrict = txtHKDistrict.Text.Trim();

                placeQuery.Remark = txtRemark.Text;
                if (radYes.Checked)
                {
                    placeQuery.Status = 1;
                }
                else
                {
                    placeQuery.Status = 0;
                }
                placeQuery.LastModUser = int.Parse(Session["UserID"].ToString());
                placeQuery.LastModDate = DateTime.Now;

                try
                {
                    if (placeManager.UpdatePlace(placeQuery))
                    {
                        Jscript.AlertAndRedirect(Resources.Messages.UpdateSuccess, "PlaceList.aspx", this.Page);
                    }
                    else
                    {
                        Jscript.Alert(Resources.Messages.UpdateFailed, this.Page);
                    }
                }
                catch
                {
                    Jscript.Alert(Resources.Messages.UpdateFailed, this.Page);
                }
            }
        }

    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        Response.Redirect("PlaceList.aspx");
    }
}
